package tjs.study.notes.dotest.redis;

import redis.clients.jedis.HostAndPort;
import redis.clients.jedis.JedisCluster;
import redis.clients.jedis.util.JedisClusterCRC16;

import java.util.HashSet;
import java.util.Set;

/**
 * Created by Nicky.Tang on 2021/11/8 9:39 下午
 *
 * @since 02.12.10
 */
public class DoTestOfRedisCluster {
    public static void main(String[] args) {
        String key = "2";
        // 这东西 可以直接看到key 的分片数，就能知道放哪个 节点
        System.out.println(JedisClusterCRC16.getSlot(key));
        Set<HostAndPort> jedisClusterNodes = new HashSet<HostAndPort>();
        // 理论上只要配集群中任何一个节点，但是应该尽可能完整，万一某一个挂了呢
        jedisClusterNodes.add(new HostAndPort("127.0.0.1", 8001));
        jedisClusterNodes.add(new HostAndPort("127.0.0.1", 9001));
        jedisClusterNodes.add(new HostAndPort("127.0.0.1", 9004));
        JedisCluster jc = new JedisCluster(jedisClusterNodes);
        System.out.println(jc.get(key));
        jc.setnx(key, "bar");
        String value = jc.get(key);
        System.out.println(value);

    }
}
